package main

import "fmt"

func main() {
	//定义
	var a [3]int
	//初始化
	var numArr = [3]int{1, 2}
	var cityArr = [2]string{"北京", "上海"}
	fmt.Println(a)
	fmt.Println(numArr)
	fmt.Println(cityArr)

	var aArr = [...]int{1, 2} //不限制元素个数，不定长数组
	fmt.Println("type of aArr: %T\n", aArr)

	var bArr = [...]int{1: 1, 2: 3} //指定索引值初始化
	fmt.Println("type of aArr: %T\n", bArr)

	//数组遍历
	for i := 0; i < len(cityArr); i++ {
		fmt.Println(cityArr[i])
	}
	for k, v := range cityArr {
		fmt.Printf("k = %d, v = %s", k, v)
	}
	//多维数组
	//多维数组只有一层可以使用 [...]
	duo := [3][2]int{
		{1, 2},
		{2, 3},
	}
	for _, d1 := range duo {
		for _, d2 := range d1 {
			fmt.Println(d2)
		}
	}
	//数组是值类型
	aa := [3]int{10, 20, 30}
	modifyArr(aa)
	fmt.Println(aa)
	vv := [3][2]int{
		{1, 2},
		{2, 3},
		{3, 4},
	}
	modifyArr2(vv)
	fmt.Println(vv)

}
func modifyArr(x [3]int) {
	x[0] = 100
}
func modifyArr2(x [3][2]int) {
	x[2][0] = 10
}
